#ifndef BLOCK_H
#define BLOCK_H

#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <locale>
#include <codecvt>

#include <graphics.h>

#include "../MyTetrisNamespace.h"

MY_TETRIS_NAMESPACE_BEGIN
static const int MAX_BLOCK_SIZE = 8;

static int SINGAL_BLOCK_LENGTH = 30;

static std::unordered_map<char, int> shape_char_2_int = {
	{'0', 0},{'1', 1},
	{'2', 2},{'3', 3},
	{'4', 4},{'5', 5},
	{'6', 6},{'7', 7},
	{'8', 8},{'9', 9},
	{'a',10},{'b',11},
	{'c',12},{'d',13},
	{'e',14},{'f',15},
	{'g',16},{'h',17},
	{'i',18},{'j',19},
	{'k',20},{'l',21},
	{'m',22},{'n',23},
	{'o',24},{'p',25},
	{'q',26},{'r',27},
	{'s',28},{'t',29},
	{'u',30},{'v',31},
	{'w',32},{'x',33},
	{'y',34},{'z',35},
	{'A',36},{'B',37},
	{'C',38},{'D',39},
	{'E',40},{'F',41},
	{'G',42},{'H',43},
	{'I',44},{'J',45},
	{'K',46},{'L',47},
	{'M',48},{'N',49},
	{'O',50},{'P',51},
	{'Q',52},{'R',53},
	{'S',54},{'T',55},
	{'U',56},{'V',57},
	{'W',58},{'X',59},
	{'Y',60},{'Z',61},
	{'!',62},{'#',63}
};

class Block
{
private:
	std::pair<int, int> left_up_coordinate;
	int block_size;
	std::vector<std::vector<int>> block_shape;
	IMAGE** skins;
public:
	Block() = default;
	Block(const int& block_size = 4, const std::string& shape = "", const std::string& skin_path = "");
	~Block();
public:
	void setLeftUpCoordinate(const int& x, const int& y);
	void setLeftUpCoordinate(const std::pair<int, int>& coordinate);
	std::pair<int, int> getLeftUpCoordinate();
	std::vector<std::vector<int>> getBlockShape()const;
	int getBlockSize();
	IMAGE getSkinAt(const int& i, const int& j);
public:
	void draw(const int& x = 0, const int& y = 0);
	void drawView(const int& x, const int& y);
};
MY_TETRIS_NAMESPACE_END

#endif
